package com.mvc.dao.impl;

import com.mvc.dao.DogDao;
import com.mvc.entity.Dog;

import java.util.List;

/**
 * @author wzm
 * @create 2023-06-26 10:19
 */
//dao实现类
public class DogDaoImpl extends BaseDao implements DogDao {
    @Override
    public int insertDog(Dog dog) {
      String sql = "insert into dog values(?,?,?)";
      return update(sql,null,dog.getName(),dog.getAge());
    }

    @Override
    public int deleteDog(Dog dog) {
        String sql = "delete from dog where id = ?";
        return update(sql,dog.getId());
    }

    @Override
    public int updateDog(Dog dog) {
        String sql = "update dog set name = ?,age = ? where id = ?";
        return update(sql,dog.getName(),dog.getAge(),dog.getId());
    }

    @Override
    public Dog selectById(Dog dog) {
        String sql ="select * from dog where id = ?";
        return selectByOne(Dog.class,sql,dog.getId());
    }

    @Override
    public List<Dog> selectByAll() {
        String sql = "select * from dog";
        return selectForList(Dog.class,sql);
    }
}
